<?php
function showbar($which,$when,$bud){
$conn = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$arr = array();
$sql="SELECT * from cr where cr_id= '$which' AND da = '$when' AND sta!= 2 AND building = '$bud'";
$result=mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
array_push($arr,$row['s_time'],$row['e_time']);
}
asort($arr);
$narr = array();
foreach($arr as $x=>$xv){
array_push($narr,$xv);
}
if(count($narr)!=0){

if($narr[0]>7){
	$first = ($narr[0] - 7)/16*100;
	$mark = "7点-".(string)$narr[0]."点：空闲";
	echo '<div class="progress-bar progress-bar-success" onmouseover="showtime(\''.$when.'-'.$bud.'-'.$which.'\',\''.$mark.'\')" role="progressbar"
         aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
         style="width: '.$first.'%;">
    </div>';
}
for($i=0;$i<count($narr);$i=$i+2){
	if($i!= 0){
		$ft = ($narr[$i]-$narr[$i-1])/16*100;
		if($ft>0){
			$mark = (string)$narr[$i-1]."点-".(string)$narr[$i]."点：空闲";
			echo '<div onmouseover="showtime(\''.$when.'-'.$bud.'-'.$which.'\',\''.$mark.'\')" class="progress-bar progress-bar-success" role="progressbar"
         aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
         style="width: '.$ft.'%;">
    </div>';
		}
	}
	$time = ($narr[$i+1]-$narr[$i])/16*100;
	$mark = (string)$narr[$i]."点-".(string)$narr[$i+1]."点：忙碌";
	echo '<div onmouseover="showtime(\''.$when.'-'.$bud.'-'.$which.'\',\''.$mark.'\')" class="progress-bar progress-bar-warning" role="progressbar"
         aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
         style="width: '.$time.'%;">
    </div>';
	}
$last = (23 - $narr[$i-1])/16*100;
if($last > 0){
	$mark = (string)$narr[$i-1]."点-23点：空闲";
	echo '<div class="progress-bar progress-bar-success" role="progressbar" onmouseover="showtime(\''.$when.'-'.$bud.'-'.$which.'\',\''.$mark.'\')" 
         aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
         style="width: '.$last.'%;">
    </div>';
}
}
else{
$mark="7点-23点：空闲";
echo '<div class="progress-bar progress-bar-success" onmouseover="showtime(\''.$when.'-'.$bud.'-'.$which.'\',\''.$mark.'\')" role="progressbar"
         aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"
         style="width:100%;">
    </div>';
}
}
?>
 